import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86186
 * Date: 2023-11-15
 * Time: 17:10
 */
@WebServlet("/request")
public class HttpServletReq extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        StringBuilder sb = new StringBuilder();
        sb.append(req.getRequestURL());
        sb.append("<br>");
        sb.append(req.getMethod());
        sb.append("<br>");
        sb.append(req.getProtocol());
        sb.append("<br>");
        sb.append(req.getQueryString());
        sb.append("<br>");
        sb.append(req.getContextPath());
        sb.append("<br>");
        Enumeration enumeration = req.getHeaderNames();
        while (enumeration.hasMoreElements()) {
            String key = (String)enumeration.nextElement();
            String value = req.getHeader(key);
            sb.append(key + ": " + value + "<br>");
        }
        resp.getWriter().write(sb.toString());
    }
}
